<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商业伙伴ID" prop="bpId">
        <el-input
          v-model="queryParams.bpId"
          placeholder="请输入商业伙伴ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPerson">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位(OP其他LP法定代表人AC实际控制人）" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职位(OP其他LP法定代表人AC实际控制人）"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机" prop="cellPhone">
        <el-input
          v-model="queryParams.cellPhone"
          placeholder="请输入手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="传真" prop="fax">
        <el-input
          v-model="queryParams.fax"
          placeholder="请输入传真"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家庭住址" prop="contactInfo">
        <el-input
          v-model="queryParams.contactInfo"
          placeholder="请输入家庭住址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="idCardNo">
        <el-input
          v-model="queryParams.idCardNo"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启用" prop="enabledFlag">
        <el-input
          v-model="queryParams.enabledFlag"
          placeholder="请输入启用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refV01">
        <el-input
          v-model="queryParams.refV01"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refV02">
        <el-input
          v-model="queryParams.refV02"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refV03">
        <el-input
          v-model="queryParams.refV03"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refV04">
        <el-input
          v-model="queryParams.refV04"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refV05">
        <el-input
          v-model="queryParams.refV05"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refN01">
        <el-input
          v-model="queryParams.refN01"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refN02">
        <el-input
          v-model="queryParams.refN02"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refN03">
        <el-input
          v-model="queryParams.refN03"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refN04">
        <el-input
          v-model="queryParams.refN04"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refN05">
        <el-input
          v-model="queryParams.refN05"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="refD01">
        <el-date-picker clearable
          v-model="queryParams.refD01"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="refD02">
        <el-date-picker clearable
          v-model="queryParams.refD02"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="refD03">
        <el-date-picker clearable
          v-model="queryParams.refD03"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="refD04">
        <el-date-picker clearable
          v-model="queryParams.refD04"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="refD05">
        <el-date-picker clearable
          v-model="queryParams.refD05"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['lease:bpMasterContactInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['lease:bpMasterContactInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['lease:bpMasterContactInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lease:bpMasterContactInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bpMasterContactInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="联系信息ID" align="center" prop="contactInfoId" />
      <el-table-column label="商业伙伴ID" align="center" prop="bpId" />
      <el-table-column label="联系人" align="center" prop="contactPerson" />
      <el-table-column label="职位(OP其他LP法定代表人AC实际控制人）" align="center" prop="position" />
      <el-table-column label="手机" align="center" prop="cellPhone" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="传真" align="center" prop="fax" />
      <el-table-column label="邮件" align="center" prop="email" />
      <el-table-column label="家庭住址" align="center" prop="contactInfo" />
      <el-table-column label="证件类型" align="center" prop="idType" />
      <el-table-column label="证件号码" align="center" prop="idCardNo" />
      <el-table-column label="启用" align="center" prop="enabledFlag" />
      <el-table-column label="${comment}" align="center" prop="refV01" />
      <el-table-column label="${comment}" align="center" prop="refV02" />
      <el-table-column label="${comment}" align="center" prop="refV03" />
      <el-table-column label="${comment}" align="center" prop="refV04" />
      <el-table-column label="${comment}" align="center" prop="refV05" />
      <el-table-column label="${comment}" align="center" prop="refN01" />
      <el-table-column label="${comment}" align="center" prop="refN02" />
      <el-table-column label="${comment}" align="center" prop="refN03" />
      <el-table-column label="${comment}" align="center" prop="refN04" />
      <el-table-column label="${comment}" align="center" prop="refN05" />
      <el-table-column label="${comment}" align="center" prop="refD01" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refD01, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="refD02" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refD02, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="refD03" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refD03, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="refD04" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refD04, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="refD05" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refD05, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['lease:bpMasterContactInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lease:bpMasterContactInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商业伙伴联系信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商业伙伴ID" prop="bpId">
          <el-input v-model="form.bpId" placeholder="请输入商业伙伴ID" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="职位(OP其他LP法定代表人AC实际控制人）" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位(OP其他LP法定代表人AC实际控制人）" />
        </el-form-item>
        <el-form-item label="手机" prop="cellPhone">
          <el-input v-model="form.cellPhone" placeholder="请输入手机" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="传真" prop="fax">
          <el-input v-model="form.fax" placeholder="请输入传真" />
        </el-form-item>
        <el-form-item label="邮件" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮件" />
        </el-form-item>
        <el-form-item label="家庭住址" prop="contactInfo">
          <el-input v-model="form.contactInfo" placeholder="请输入家庭住址" />
        </el-form-item>
        <el-form-item label="证件号码" prop="idCardNo">
          <el-input v-model="form.idCardNo" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="启用" prop="enabledFlag">
          <el-input v-model="form.enabledFlag" placeholder="请输入启用" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refV01">
          <el-input v-model="form.refV01" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refV02">
          <el-input v-model="form.refV02" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refV03">
          <el-input v-model="form.refV03" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refV04">
          <el-input v-model="form.refV04" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refV05">
          <el-input v-model="form.refV05" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refN01">
          <el-input v-model="form.refN01" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refN02">
          <el-input v-model="form.refN02" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refN03">
          <el-input v-model="form.refN03" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refN04">
          <el-input v-model="form.refN04" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refN05">
          <el-input v-model="form.refN05" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="refD01">
          <el-date-picker clearable
            v-model="form.refD01"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="refD02">
          <el-date-picker clearable
            v-model="form.refD02"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="refD03">
          <el-date-picker clearable
            v-model="form.refD03"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="refD04">
          <el-date-picker clearable
            v-model="form.refD04"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="refD05">
          <el-date-picker clearable
            v-model="form.refD05"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBpMasterContactInfo, getBpMasterContactInfo, delBpMasterContactInfo, addBpMasterContactInfo, updateBpMasterContactInfo } from "@/api/lease/bpMasterContactInfo";

export default {
  name: "BpMasterContactInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商业伙伴联系信息表格数据
      bpMasterContactInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bpId: null,
        contactPerson: null,
        position: null,
        cellPhone: null,
        phone: null,
        fax: null,
        email: null,
        contactInfo: null,
        idType: null,
        idCardNo: null,
        enabledFlag: null,
        refV01: null,
        refV02: null,
        refV03: null,
        refV04: null,
        refV05: null,
        refN01: null,
        refN02: null,
        refN03: null,
        refN04: null,
        refN05: null,
        refD01: null,
        refD02: null,
        refD03: null,
        refD04: null,
        refD05: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bpId: [
          { required: true, message: "商业伙伴ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商业伙伴联系信息列表 */
    getList() {
      this.loading = true;
      listBpMasterContactInfo(this.queryParams).then(response => {
        this.bpMasterContactInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contactInfoId: null,
        bpId: null,
        contactPerson: null,
        position: null,
        cellPhone: null,
        phone: null,
        fax: null,
        email: null,
        contactInfo: null,
        idType: null,
        idCardNo: null,
        enabledFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        refV01: null,
        refV02: null,
        refV03: null,
        refV04: null,
        refV05: null,
        refN01: null,
        refN02: null,
        refN03: null,
        refN04: null,
        refN05: null,
        refD01: null,
        refD02: null,
        refD03: null,
        refD04: null,
        refD05: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.contactInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商业伙伴联系信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const contactInfoId = row.contactInfoId || this.ids
      getBpMasterContactInfo(contactInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商业伙伴联系信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.contactInfoId != null) {
            updateBpMasterContactInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBpMasterContactInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contactInfoIds = row.contactInfoId || this.ids;
      this.$modal.confirm('是否确认删除商业伙伴联系信息编号为"' + contactInfoIds + '"的数据项？').then(function() {
        return delBpMasterContactInfo(contactInfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lease/bpMasterContactInfo/export', {
        ...this.queryParams
      }, `bpMasterContactInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
